<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class CreateProjectRequest extends FormRequest
{   
    protected $errorBag = 'create';
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'=>[
                'required',
                Rule::unique('projects')->where(function($query){
                    return $query->where('user_id',request()->user()->id);
                })
            ],
            'thumb'=>'image'
        ];
    }
    public function messages(){
        return [
            'name.required'=>'项目名称必须填写',
            'name.unique'=>'项目名称不能重复',
            'thumb.image'=>'图片格式不正确',
        ];
    }
}
